package com.sdleyou.treepro.manager.api.achievement;

import com.sdleyou.treepro.common.model.utils.ResultVOUtil;
import com.sdleyou.treepro.common.model.vo.ResultVO;
import com.sdleyou.treepro.common.service.AchievementManager;
import com.sdleyou.treepro.common.service.CardManager;
import com.sdleyou.treepro.system.version.ApiVersion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.math.BigDecimal;

/**
 * 成就控制器
 */
@RestController
@RequestMapping("/api")
public class ManagerAchievementController {

    @Autowired
    private CardManager cardManager;
    @Autowired
    private AchievementManager achievementManager;

    /**
     * 创建成就信息
     */
    @ApiVersion(1)
    @PostMapping("/{version}/manager/achievement")
    public ResultVO createCard(@RequestParam(name = "total_target") @NotEmpty(message = "全网目标种树量") Long totalTarget,
                               @RequestParam(name = "current_target") @NotEmpty(message = "全网当前种树量")Long currentTarget,
                               @RequestParam(name = "total_step") @NotEmpty(message = "累计捐赠步数")Long totalStep) {
        achievementManager.createAchievement(totalTarget, currentTarget, totalStep);
        return ResultVOUtil.success();
    }

    /**
     * 修改成就信息
     */
    @ApiVersion(1)
    @PutMapping("/{version}/manager/achievement/{card_id}")
    public ResultVO updateCard(@RequestParam(name = "a_id") @NotEmpty(message = "id不能为空")String aId,
                               @RequestParam(name = "total_target") @NotEmpty(message = "全网目标种树量") Long totalTarget,
                               @RequestParam(name = "current_target") @NotEmpty(message = "全网当前种树量")Long currentTarget,
                               @RequestParam(name = "total_step") @NotEmpty(message = "累计捐赠步数")Long totalStep) {
        achievementManager.updateAchievement(aId, totalTarget, currentTarget, totalStep);
        return ResultVOUtil.success();
    }
}
